package cn.richard.home.wdget

import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import cn.richard.home.R

/**
 *
 * @ProjectName: PicApp
 * @Author: wuzhiguo@aiforward.com
 * @CreateDate: 2021/9/2 7:16 下午
 * @Description:
 */
class PicListDecoration: RecyclerView.ItemDecoration() {

    override fun getItemOffsets(
        outRect: Rect,
        view: View,
        parent: RecyclerView,
        state: RecyclerView.State
    ) {
        super.getItemOffsets(outRect, view, parent, state)

        val lineSpace = view.resources.getDimension(R.dimen.dp_6)
        if (parent.getChildAdapterPosition(view) % 2 == 0) {
            outRect.left = lineSpace.toInt()
            outRect.right = (lineSpace / 2).toInt()
            outRect.top = lineSpace.toInt()
            outRect.bottom = 0
        } else {
            outRect.left = (lineSpace / 2).toInt()
            outRect.right = lineSpace.toInt()
            outRect.top = lineSpace.toInt()
            outRect.bottom = 0
        }
    }
}